import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../common.dart';

class Collect extends StatefulWidget {
  Collect({super.key});

  @override
  State<Collect> createState() => _SettingPageState();
}

class _SettingPageState extends State<Collect> {
  List arr = [];

  getInfo(url) {
    getData(url: url).then((res) {
      if (res != null) {
        arr = res;
        setState(() {});
      }
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getInfo('/index/like_goods');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xffffffff),
        title: Text('我的收藏'),
        centerTitle: true,
        leading: buildBackButton(context),
      ),
      body: ListView(
        padding: EdgeInsets.only(left: 15, right: 15),
        children: [
          if (arr.isEmpty) isdata(),
          for (var item in arr.asMap().entries)
            GestureDetector(
              onTap: () {
                toNamed('/home/detail?uuid=${item.value['uuid']}');
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  color: Color(0XFFF8F9FD),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child: Row(
                        children: [
                          wImage(
                            url: '${item.value['thumb']}',
                            width: 60,
                            height: 60,
                            borderRadius: 8,
                          ),
                          SizedBox(width: 12),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                width: 180,
                                child: RichText(
                                  maxLines: 2,
                                  text: TextSpan(
                                    children: [
                                      TextSpan(
                                        text: '${item.value['title']}',
                                        style: TextStyle(
                                          fontSize: 13,
                                          fontWeight: FontWeight.bold,
                                        ),
                                      ),
                                      WidgetSpan(
                                        child: setInteger(
                                          item.value['vlv'],
                                          w: 15,
                                        ),
                                        alignment: PlaceholderAlignment.bottom,
                                      ),
                                    ],
                                    style: TextStyle(color: Color(0XFF0F172B)),
                                  ),
                                ),
                              ),
                              SizedBox(height: 3),
                              wText(
                                text: '来自 ${item.value['issue']}',
                                size: 12,
                                color: '838894',
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        postData(
                          url: '/market/unLikeGoods',
                          data: {'product_id': '${item.value['id']}'},
                        ).then((res) {
                          if (res != null) {
                            eventBus.fire(UserLoginEvent('张伟'));
                            showTost('取消成功');
                            arr.removeAt(item.key);
                            setState(() {});
                          }
                        });
                      },
                      child: wImage(url: 'lanxing', width: 28),
                    ),
                  ],
                ),
              ),
            ),
        ],
      ),
    );
  }
}
